<template>
  <div class="app-container">
    <!--查询-->
    <el-form :inline="true">
      <el-form-item label=" 自增id">
        <el-input
          v-model="searchForm.id"
          placeholder=" 自增id"
          clearable
          @blur="fetchList"
          @keyup.enter.native="fetchList"
        />
      </el-form-item>

      <el-form-item label=" 关联id">
        <el-input
          v-model="searchForm.objId"
          placeholder=" 关联id"
          clearable
          @blur="fetchList"
          @keyup.enter.native="fetchList"
        />
      </el-form-item>

      <el-form-item label=" 点赞类型">
        <el-select
          clearable
          @blur="fetchList"
          @keyup.enter.native="fetchList"
          v-model="searchForm.type">
          <el-option label="回答" :value="0" />
          <el-option label="评论" :value="1" />
          <el-option label="公司" :value="2" />
          <el-option label="部门" :value="3" />
        </el-select>
      </el-form-item>

      <search-buttons
        :fetch-data="fetchList"
        :export-flag="false"
        :add-flag="false"
      />
    </el-form>
    <!--表格-->
    <el-table :data="tableData" border stripe>
      <el-table-column type="index" width="50" label="序号" />
      <el-table-column prop="id" label=" 自增id" />
      <el-table-column prop="objId" label=" 关联id" />
      <el-table-column prop="type" label="点赞类型" :formatter="typeFormatter"/>
      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <operation-buttons
            :row="scope.row"
            :del-fun="delLikeRecordsById"
            :show-detail="false"
            :show-edit="false"
          />
        </template>
      </el-table-column>
    </el-table>
    <div>
      <!-- 分页 -->
      <pagination
        :page.sync="searchForm.currentPage"
        :total="total"
        :limit.sync="searchForm.pageSize"
        @pagination="fetchList"
      />
    </div>
  </div>
</template>
<script>
import likeRecords from '@/api/likeRecords'
import Pagination from '@/components/Pagination/index'
import SearchButtons from '@/components/SearchButtons/index'
import OperationButtons from '@/components/OperationButtons/index'
export default {
  components: {
    Pagination,
    SearchButtons,
    OperationButtons
  },
  data() {
    return {
      name: 'LikeRecords',
      searchForm: {
        currentPage: 1,
        pageSize: 10
      },
      total: 0,
      tableData: []
    }
  },
  created() {
    this.fetchList()
  },
  methods: {
    fetchList() {
      likeRecords.fetchList({ ...this.searchForm }).then(resp => {
        this.tableData = resp.data.data
        this.total = resp.data.total
        this.searchForm.pageNum = resp.data.pageNum
        this.searchForm.currentPage = resp.data.currentPage
      })
    },
    delLikeRecordsById(id) {
      likeRecords.delById(id).then(resp => {
        this.$message.info(resp.message)
      })
    },
    clearSearchForm() {
      this.searchForm = {}
    },
    downloadTemplate() {
      window.href.location = 'http://localhost:9527/likeRecords/template'
    },
    export2Excel() {
      likeRecords.export2Excel({ ...this.searchForm })
    },
    typeFormatter(row, column) {
      switch (row.type) {
        case 0:
          return '回答'
        case 2:
          return '公司'
        case 3:
          return '部门'
        default:
          return '评论'
      }
    }
  }
}
</script>
<style>

</style>
